package cn.taoci.hello;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;


@Service
public class DBServiceImpl implements DBService {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Autowired
    private RedisTemplate<String, Long> redisTemplate;

    @Override
    public int save(String username, String sex, String job, String phoneNumber, String organizationName) {
        String sql = "insert into registration (username, gender, use_post, use_phone, company_name) values (?,?,?,?,?)";
        Object[] obj = {username, sex, job, phoneNumber, organizationName};
        return jdbcTemplate.update(sql, obj);
    }

    @Override
    public long accessCount() {
        return redisTemplate.boundValueOps("AccessCounter").increment(1L);
    }
}
